<template>
  <div class="container">

    <div>

    </div>

    <div style="width: 100%;height: 100%;background-color: #ffffff;">

      <van-form >
        <van-empty
          image="https://sqyjph.oss-cn-qingdao.aliyuncs.com/quanzi/16522398639898313.png"
          image-size="80"
          description="保存成功"
        />

        <div style="text-align: center;font-size: 18px;padding-left: 20px;padding-right: 20px;padding-top: 30px;padding-bottom: 280px;">
          稍后会有客服人员和您联系对接。
        </div>
      </van-form>


    </div>
  </div>
</template>

<script>
  import {saveReport,saveReportReadNum ,uploadShareImg,saveDkinfo} from 'api/api'
  import {Toast} from 'vant'
  export default {
    name: 'myquanzi',
    data() {
      return {
        xq1:'',
        xq2:'',
        xq3:'',
        xq4:'',
        xq5:'',
        xq6:'',
        xq7:'',
        xq8:'',
        xq9:'',
        xq10:'',
        agencyid:'',
        gsname:'',
        frname:'',
        frsfzh:'',
        dkje:'',
        ppname:'',
        phone:'',
        fileList:[],
        images:[],

      }
    },
    created() {

      const agencyId = this.$route.query.agencyId
      this.agencyid = agencyId
      this.saveReportReadNum()

      let  xtname = this.viewczxt()
      let that = this
      if(xtname == "Android"){
        document.addEventListener('message', function(msg) {
          console.log(msg);
          that.images.push(msg.data + '')
          //如果需要获取msg里面的值。需要msg.data。
          //当时这个坑卡了好久，因为不方便查看msg里面的东西，直接用msg.是获取不到东西的。
          //还有，记住使用  JSON.parse(msg.data)  才能获取到你的东西!!!
        });

      }else{
        window.onload = function() {
          window.addEventListener("message", function(event) {
            console.log('app发送信息：')
            console.log(event.data)
            that.images.push(msg.data + '')
          });
        }
      }

    },
    methods: {
      //识别操作系统
      viewczxt(){
        var u = navigator.userAgent, app = navigator.appVersion;
        var isXiaomi = u.indexOf('XiaoMi') > -1; // 小米手机
        var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; // 其它安卓
        var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); // ios
        if (isAndroid) {
          return "Android"
        }else if (isIOS) {
          if(isXiaomi) {
            return  "Android"
          }else {
            return  "Ios"
          }
        }
      },

      onClickLeft() {
        this.$router.go(-1) // 返回上一层
      },

      onSubmit(){
        let param = {}
        param.agencyid = this.agencyid
        param.phone = this.phone
        param.frname = this.frname
        param.frsfzh = this.frsfzh
        param.gsname = this.gsname
        param.dkje = this.dkje
        param.ppname = this.ppname
        param.yyzzurl = this.images.toString()



        if(!param.frname){
          Toast.fail('请输入法人姓名')
          return
        }

        if(!param.frsfzh){
          Toast.fail('请输入法人身份证号')
          return
        }

        if(!param.gsname){
          Toast.fail('请输入公司名称')
          return
        }

        if(!param.dkje){
          Toast.fail('请输入贷款金额')
          return
        }

        if(!param.ppname){
          Toast.fail('请输入代理品牌')
          return
        }

        if(!param.phone){
          Toast.fail('请输入您的手机号，以便跟您联系')
          return
        }


        saveDkinfo(param).then(response => {
          if (response.code === 200) {
            Toast.success('保存成功')
          }else{
            Toast.fail(response.msg)
          }
        })

      },

      saveReportReadNum(){
        let param = {}
        param.dictType = 'report_readed'
        saveReportReadNum(param).then(response => {
          if (response.code === 200) {

          }else{
            // Toast.fail(response.msg)
          }
        })
      },


      /**
       * 删除附件
       * @param {*} e
       */
      delImgs:function(item){
        console.log(item)
        console.log(this.images)
        let that = this
        let images = that.images
        let length = images.length
        for(var i=0;i<length;i++){
          if(images[i] == item.item){
            that.images.splice(i,1)
          }
        }
      },

      selectTp(){
        window.postMessage('camera');
        document.getElementById("uploadfileid").click();
      },

      fileSelected() {
        var file = document.getElementById('uploadfileid').files[0];
        if (file) {
          var fileSize = 0;
          if (file.size > 1024 * 1024)
            fileSize = (Math.round(file.size * 100 / (1024 * 1024)) / 100).toString() + 'MB';
          else
            fileSize = (Math.round(file.size * 100 / 1024) / 100).toString() + 'KB';

          console.log(file.name)
          console.log(fileSize)
          console.log(file.type)

          let formData = new FormData();
          formData.append("file", file);
          formData.append("type","quanzi")
          let fileList = []
          uploadShareImg(formData).then(response => {
            console.log(response)
            if(response.code == 200 ){
              fileList.push(response.data.url)
              this.images.push(response.data.url+'')
              this.fileList.concat(fileList)
              console.log(this.fileList)
              console.log(this.images)
            }
          });

        }
      }


    }

  }
</script>

<style scoped>

  .container{
    background-color: white;
    height: auto;
  }

  .columnr{
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: flex-start;
  }

  .rownr{
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: flex-start;
    width: 100%;
    font-size: 16px;
  }

  .content{
    font-size: 16px;
    padding:10px;
    width: 80%;
  }

  .text{
    text-indent: 32px;
    padding-left: 10px;
    padding-right: 10px;
    font-size: 16px;
    padding-top: 10px;
    line-height: 200%;
  }

  .text1{
    padding-left: 10px;
    padding-right: 10px;
    font-size: 14px;
    padding-top: 15px;
    line-height: 200%;
  }

  .box {
    position: relative;
    display: inline-block;
    padding-left: 12px;
  }
  .box .clear {
    position: absolute;
    top: 0;
    right: 0;
  }


</style>
